package com.shensi.adminCollect.service.integral.impl;

import com.alibaba.fastjson.JSONObject;
import com.shensi.api.pay.client.RedisConsumptionThemeClient;
import com.shensi.common.core.domain.UniversalRedisMessageDto;
import com.shensi.common.core.enums.WxConsumptionMessageEnum;
import com.shensi.common.core.utils.DateUtils;
import com.shensi.adminCollect.enums.integral.integralTypeEnum;
import com.shensi.adminCollect.domain.integral.CustomerPointsRecord;
import com.shensi.adminCollect.mapper.integral.CustomerPointsRecordMapper;
import com.shensi.adminCollect.service.integral.ICustomerPointsRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 客户积分记录Service业务层处理
 * 
 * @author qujia
 * @date 2021-03-17
 */
@Service
public class CustomerPointsRecordServiceImpl implements ICustomerPointsRecordService 
{
    @Autowired
    private CustomerPointsRecordMapper customerPointsRecordMapper;

    @Autowired
    private RedisTemplate redisTemplate;
    @Value("${message.channel}")
    private String channel;

    @Autowired
    private RedisConsumptionThemeClient redisConsumptionThemeClient;
    /**
     * 查询客户积分记录
     * 
     * @param id 客户积分记录ID
     * @return 客户积分记录
     */
    @Override
    public CustomerPointsRecord selectCustomerPointsRecordById(Long id)
    {
        return customerPointsRecordMapper.selectCustomerPointsRecordById(id);
    }

    /**
     * 查询客户积分记录列表
     * 
     * @param customerPointsRecord 客户积分记录
     * @return 客户积分记录
     */
    @Override
    public List<CustomerPointsRecord> selectCustomerPointsRecordList(CustomerPointsRecord customerPointsRecord)
    {
        return customerPointsRecordMapper.selectCustomerPointsRecordList(customerPointsRecord);
    }

    /**
     * 新增客户积分记录
     * 
     * @param customerPointsRecord 客户积分记录
     * @return 结果
     */
    @Override
    public int insertCustomerPointsRecord(CustomerPointsRecord customerPointsRecord)
    {
        customerPointsRecord.setCreateTime(DateUtils.getNowDate());
        customerPointsRecord.setAction(integralTypeEnum.MANUAL_ADDITION);

        return customerPointsRecordMapper.insertCustomerPointsRecord(customerPointsRecord);
    }

    /**
     * 修改客户积分记录
     * 
     * @param customerPointsRecord 客户积分记录
     * @return 结果
     */
    @Override
    public int updateCustomerPointsRecord(CustomerPointsRecord customerPointsRecord)
    {
        return customerPointsRecordMapper.updateCustomerPointsRecord(customerPointsRecord);
    }

    /**
     * 批量删除客户积分记录
     * 
     * @param ids 需要删除的客户积分记录ID
     * @return 结果
     */
    @Override
    public int deleteCustomerPointsRecordByIds(Long[] ids)
    {
        return customerPointsRecordMapper.deleteCustomerPointsRecordByIds(ids);
    }

    /**
     * 删除客户积分记录信息
     * 
     * @param id 客户积分记录ID
     * @return 结果
     */
    @Override
    public int deleteCustomerPointsRecordById(Long id)
    {
        return customerPointsRecordMapper.deleteCustomerPointsRecordById(id);
    }

    @Override
    public List<CustomerPointsRecord> selectList(CustomerPointsRecord record){
        return customerPointsRecordMapper.selectList(record);
    }

    @Override
    public CustomerPointsRecord getOne(CustomerPointsRecord record){
        return customerPointsRecordMapper.getOne(record);
    }

    @Override
    public void wxgzhIntegralPush(CustomerPointsRecord record) {
        UniversalRedisMessageDto dto=new UniversalRedisMessageDto();
        dto.setData(JSONObject.toJSONString(record));
        dto.setMessageType(WxConsumptionMessageEnum.INTEGRAL_MESSAGE_PUSH.getValue());
        dto.setTitle(WxConsumptionMessageEnum.INTEGRAL_MESSAGE_PUSH.getKey());
        dto.setChannel(channel);
        //redisTemplate.convertAndSend(channel, dto);
        redisConsumptionThemeClient.publishMessageUse(dto);
    }

}
